﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TathamOddie.OpenSearchValidator.Logic.UnitTests
{
	[TestClass]
	public class XhtmlParserTests
	{
		[TestMethod]
		public void ParsesBasicAnchorTag()
		{
			var html = "<a href=\"hello.aspx\"></a>";
			var output = XhtmlParser.ParseTags(html, "a");
			
			Assert.AreEqual(1, output.Length);
			Assert.AreEqual("a", output[0].TagName);
			Assert.AreEqual(1, output[0].Attributes.Keys.Count);
			Assert.AreEqual("hello.aspx", output[0].Attributes["href"]);
		}

		[TestMethod]
		public void ParsesOpenSearchTag()
		{
			var html = "abc \r\n <link rel=\"search\"\r\n\t type=\"application/opensearchdescription+xml\" href=\"/OpenSearch.aspx\" title=\"GraysOnline Search\" /> \r\nabc";
			var output = XhtmlParser.ParseTags(html, "link");

			Assert.AreEqual(1, output.Length);
			Assert.AreEqual("link", output[0].TagName);
			Assert.AreEqual(4, output[0].Attributes.Keys.Count);
			Assert.AreEqual("search", output[0].Attributes["rel"]);
			Assert.AreEqual("application/opensearchdescription+xml", output[0].Attributes["type"]);
			Assert.AreEqual("/OpenSearch.aspx", output[0].Attributes["href"]);
			Assert.AreEqual("GraysOnline Search", output[0].Attributes["title"]);
		}
	}
}